package controller

import (
	"fx_swift_ifcgate_agent/api"
	"fx_swift_ifcgate_agent/internal/service"
	"fx_swift_ifcgate_agent/pkg/code"
	"fx_swift_ifcgate_agent/pkg/enum"
	"fx_swift_ifcgate_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

func QueryAgentApply(c *gin.Context) {
	result, err := service.NewAgentSrv().QueryAgentApply(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func UploadEnterpriseInfo(c *gin.Context) {
	req := &api.EnterpriseAccountApplyReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	err := service.NewAgentSrv().UploadEnterpriseInfo(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

// 开户趋势
func MerOpenTrend(c *gin.Context) {
	result, err := service.NewAgentSrv().MerOpenTrend(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 开户趋势-按时间范围查询
func MerOpenTrendDynamic(c *gin.Context) {
	req := &api.MerOpenTrendReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrBind, err.Error())
		return
	}

	result, err := service.NewAgentSrv().MerOpenTrendDynamic(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 账户状态
func GetMerStatusBoss(c *gin.Context) {
	//req := &api.MerOpenTrendReq{}
	//if err := c.ShouldBindJSON(&req); err != nil {
	//	code.Fail(c, http.StatusBadRequest, code.ErrBind, err.Error())
	//	return
	//}

	result, err := service.NewAgentSrv().GetMerStatusBoss(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// kyc认证列表
func GetAllMerChantAuditList(c *gin.Context) {
	req := &api.MerChantBossReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrBind, err.Error())
		return
	}

	result, err := service.NewAgentSrv().GetAllMerChantAuditList(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 企业列表
func GetAllMerChantSuccList(c *gin.Context) {
	req := &api.MerChantBossReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrBind, err.Error())
		return
	}

	result, err := service.NewAgentSrv().GetAllMerChantSuccList(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// BOSS端获取KYC认证资料详情
func GetMerChantBoss(c *gin.Context) {
	acct := c.Query("account")
	result, err := service.NewAgentSrv().GetMerChantTemp(c, acct)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取boss端待审核企业家数
func GetAuditNums(c *gin.Context) {
	result, err := service.NewAgentSrv().GetAuditNums(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 根据业务性质类型获取业务性质
func QueryBusinessNature(c *gin.Context) {
	natureType := c.Query("natureType")
	result, err := service.NewAgentSrv().QueryBusinessNature(c, natureType)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取资金来源
func QuerySourceFund(c *gin.Context) {
	result, err := service.NewAgentSrv().QuerySourceFund(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取付款目的
func QueryPaymentPurpose(c *gin.Context) {
	result, err := service.NewAgentSrv().QueryPaymentPurpose(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取营业额
func QueryTurnover(c *gin.Context) {
	result, err := enum.InitTurnover()
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取交易量
func QueryTransaction(c *gin.Context) {
	result, err := enum.InitTransaction()
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 公司类型
func GetCompanyType(c *gin.Context) {
	result, err := service.NewAgentSrv().GetCompanyType(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
